from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import Unicode

from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension

from sqlalchemy import Text


from scp.modelo.models import Base

__all__ = [ 'Rol' ]


from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, backref


from scp.modelo.Permiso import Permiso



association_table = Table('rol_permiso', Base.metadata,
    Column('rol_id', Integer, ForeignKey('rol.id')),
    Column('permiso_id', Integer, ForeignKey('permiso.id'))
)


class Rol(Base):
	""" Clase que se mapea a la tabla de Roles. """
	__tablename__ = 'rol'
	id = Column(Integer, primary_key=True)
	nombre = Column(Unicode(20), unique=True)
	descripcion = Column(Unicode(100))
	permisos = relationship("Permiso",
					secondary=association_table)
    
